<template>
  <div class="container">
    <h2>基础饼状图</h2>
    <div class="chart-container">
      <div id="basicPieChart" style="height:500px"></div>
    </div>
  </div>
</template>

<script>
export default {
  name: "basicPieChart",
  data() {
    return {
      option: {
        title: {
          text: "基础饼状图",
          subtext: "subtext",
          left: "center",
        },
        tooltip: {
          trigger: "item",
        },
        legend: {
          orient: "vertical",
          left: "left",
        },
        series: [
          {
            name: "Access From",
            type: "pie",
            radius: "50%",
            data: [
              { value: 1048, name: "Search Engine" },
              { value: 735, name: "Direct" },
              { value: 580, name: "Email" },
              { value: 484, name: "Union Ads" },
              { value: 300, name: "Video Ads" },
            ],
            // 高亮状态的扇区和标签样式
            emphasis: {
              itemStyle: {
                shadowBlur: 10, // 阴影
                shadowOffsetX: 10, // 阴影
                shadowColor: "rgba(0, 0, 0, 0.5)",
              },
            },
          },
        ],
      },
    };
  },
  mounted() {
    this.getLineChart();
  },
  methods: {
    // 设置折线图
    getLineChart() {
      this.lineChart = this.$echart.init(
        document.getElementById("basicPieChart")
      );
      this.lineChart.setOption(this.option);
    },
  },
};
</script>

<style lang="less">
.chart-container {
  canvas {
    // width: 200px !important;
  }
}
</style>